package exp4.test1;

import exp4.test1.MarGraph;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.*;

/**
 * Created by 春旺 on 2017/11/19.
 */
public class MarGraphTest {
    MarGraph graph = new MarGraph();
    @Test
    public void addVertex() throws Exception {
        assertEquals(0,graph.size());
        graph.Graph(4);
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        graph.addVertex(4);
        assertEquals(4,graph.size());
    }

    @Test
    public void addEdges() throws Exception {
        graph.Graph(4);
        assertEquals(0,graph.edgesNumber());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        graph.addVertex(4);
        assertEquals(0,graph.edgesNumber());
        graph.addEdges(1,2);
        graph.addEdges(1,3);
        graph.addEdges(1,4);
        graph.addEdges(2,3);
        graph.addEdges(4,3);
        graph.addEdges(2,3);
        assertEquals(6,graph.edgesNumber());
    }

    @Test
    public void removeVertex() throws Exception {
        graph.Graph(4);
        assertEquals(0,graph.edgesNumber());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        graph.addVertex(4);
        assertEquals(0,graph.edgesNumber());
        graph.addEdges(1,2);
        graph.addEdges(1,3);
        graph.addEdges(1,4);
        graph.addEdges(2,3);
        graph.addEdges(4,3);
        graph.addEdges(2,4);
        assertEquals(6,graph.edgesNumber());
        graph.removeVertex(1);
        assertEquals(3,graph.size());
        assertEquals(3,graph.edgesNumber());
    }

    @Test
    public void removeEdges() throws Exception {
        graph.Graph(4);
        assertEquals(0,graph.edgesNumber());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        graph.addVertex(4);
        assertEquals(0,graph.edgesNumber());
        graph.addEdges(1,2);
        graph.addEdges(1,3);
        graph.addEdges(1,4);
        graph.addEdges(2,3);
        graph.addEdges(4,3);
        graph.addEdges(2,4);
        assertEquals(6,graph.edgesNumber());
        graph.removeEdges(1,4);
        assertEquals(4,graph.size());
        assertEquals(5,graph.edgesNumber());
        graph.removeEdges(1,3);
        assertEquals(4,graph.edgesNumber());
    }

    @Test
    public void size() throws Exception {
        graph.Graph(4);
        assertEquals(0,graph.size());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        assertEquals(3,graph.size());
    }

    @Test
    public void isEmpty() throws Exception {
        graph.Graph(4);
        assertEquals(true,graph.isEmpty());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        assertEquals(false,graph.isEmpty());
    }

    @Test
    public void iteratorBFS() throws Exception {
        graph.Graph(4);
        assertEquals(0,graph.edgesNumber());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        graph.addVertex(4);
        assertEquals(0,graph.edgesNumber());
        graph.addEdges(1,2);
        graph.addEdges(1,3);
        graph.addEdges(2,3);
        graph.addEdges(2,4);
        graph.addEdges(3,4);

        ArrayList arrayList = new ArrayList();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        assertEquals(arrayList,graph.iteratorBFS(0));
    }

    @Test
    public void iteratorDSF() throws Exception {
        graph.Graph(4);
        assertEquals(0,graph.edgesNumber());
        graph.addVertex(1);
        graph.addVertex(2);
        graph.addVertex(3);
        graph.addVertex(4);
        assertEquals(0,graph.edgesNumber());
        graph.addEdges(1,2);
        graph.addEdges(1,3);
        graph.addEdges(2,3);
        graph.addEdges(2,4);
        graph.addEdges(3,4);

        ArrayList arrayList = new ArrayList();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        assertEquals(arrayList,graph.iteratorBFS(1));
    }

}